<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-island-scenic__isscenicspot">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.scenicSpotName"
            placeholder="景点名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.scenicName"
            placeholder="所属区域"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in scenicOptions"
              :key="item.id"
              :label="item.scenicName"
              :value="item.scenicName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.realName"
            placeholder="游客名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.linkName"
            placeholder="联系人"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.linkMobile"
            placeholder="联系方式"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.status" placeholder="订单状态" clearable>
            <el-option
              :value="item.val"
              v-for="item in payState"
              :key="item.val"
              :label="item.label"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <ren-select
            v-model="dataForm.payType"
            dict-type="pay_type"
            placeholder="请选择支付方式"
            style="width: 100%"
          ></ren-select>
        </el-form-item>
        <!-- 支付时间 -->
        <el-form-item>
          <el-date-picker
            v-model="value1"
            type="datetimerange"
            range-separator="至"
            start-placeholder="支付开始日期"
            end-placeholder="支付结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <!-- 核销时间 -->
        <el-form-item>
          <el-date-picker
            v-model="value2"
            type="datetimerange"
            range-separator="至"
            start-placeholder="核销开始日期"
            end-placeholder="核销结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.orderCode"
            placeholder="订单编号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('scenic:so:centerExport')"
            type="primary"
            @click="exportHandle()"
            >导出</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%"
        :height="he"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="orderCode"
          label="订单编号"
          header-align="center"
          align="center"
          min-width="160px"
        ></el-table-column>
        <el-table-column
          prop="orderAmount"
          label="订单总额"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="scenicName"
          label="区域名称"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="scenicSpotName"
          label="景区名称"
          header-align="center"
          align="center"
          min-width="150px"
        ></el-table-column>
        <el-table-column
          prop="linkName"
          label="联系人"
          header-align="center"
          align="center"
          min-width="100px"
        ></el-table-column>
        <!-- <el-table-column prop="linkMobile" label="联系电话" header-align="center" align="center" min-width="120px"></el-table-column> -->
        <el-table-column
          label="联系电话"
          header-align="center"
          min-width="120"
          align="center"
        >
          <template slot-scope="scope">
            <i @click="showReal = scope.$index">{{
              scope.$index === showReal
                ? scope.row.realPhone
                : scope.row.linkMobile
            }}</i>
          </template>
        </el-table-column>
        <el-table-column
          prop="status"
          label="订单状态"
          header-align="center"
          align="center"
          min-width="120px"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              :style="{
                background: statusColor[scope.row.status],
                color: '#fff',
              }"
              >{{ scope.row.status | delStatus }}</el-button
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="createDate"
          label="下单时间"
          header-align="center"
          align="center"
          min-width="170px"
        ></el-table-column>
        <el-table-column
          prop="payTime"
          label="支付时间"
          header-align="center"
          align="center"
          min-width="170px"
        ></el-table-column>
        <el-table-column
          prop="orderType"
          label="支付方式"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{ $getDictLabel("pay_type", scope.row.payType) }}
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button
              v-if="$hasPermission('scenic:so:centerInfo')"
              type="text"
              size="small"
              @click="viewHandle(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 详情 -->
      <look-detail
        v-if="lookDetailVisible"
        ref="lookDetail"
        :orderCode="orderCode"
        :url="url"
        :type="type"
      ></look-detail>
    </div>
  </el-card>
</template>

<script>
var that;
import mixinViewModule from "@/mixins/view-module";
import lookDetail from "./detail.vue";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
        he:'auto',
      disabled: false,
      mixinViewModuleOptions: {
        getDataListURL: "/scenic/scenic-order/querySceOrderPageByPc",
        getDataListIsPage: true,
        exportURL: "/scenic/scenic-order/exportScenicOrderList",
      },
      scenicOptions: [],
      value1: [],
      value2: [],
      dataForm: {
        status: "",
        orderType: "",
        payType: "",
        linkMobile: "",
        payTimeEndDate: "",
        payTimeOpenDate: "",
        realName: "",
        scenicName: "",
        scenicSpotName: "",
        updateEndDate: "",
        updateOpenDate: "",
      },
      statusColor: {
        0: "#FF4141",
        1: "#409eff",
        "-1": "#CCC",
        "-2": "#FF9C3D",
        "-3": "#CCC",
        3: "#CCC",
      },
      orderCode: "",
      url: "",
      type: "",
      orderTypes: [
        {
          val: 1,
          label: "景区门票",
        },
        {
          val: 7,
          label: "船+景",
        },
      ],
      payState: [
        {
          val: 3,
          label: "已完成",
        },
        {
          val: -3,
          label: "已退款",
        },
        {
          val: -2,
          label: "退款中",
        },
        {
          val: -1,
          label: "已取消",
        },
        {
          val: 1,
          label: "已支付",
        },
        {
          val: 0,
          label: "待支付",
        },
      ],
      showReal: "",
    };
  },
  created() {
    that = this;
    this.getScenicOptions();
  },
  components: {
    lookDetail,
  },
  watch: {
    dataList(newval, oldval) {
      if (newval != oldval) {
        this.he = "auto";
        setTimeout(() => {
          this.he = "calc(100vh - 330px)";
        }, 500);
      }
    },
    value1(newval, oldval) {
      if (newval) {
        if (newval != oldval) {
          this.dataForm.payTimeOpenDate = newval[0];
          this.dataForm.payTimeEndDate = newval[1];
        }
      } else {
        this.dataForm.payTimeOpenDate = "";
        this.dataForm.payTimeEndDate = "";
      }
    },
    value2(newval, oldval) {
      if (newval) {
        if (newval != oldval) {
          this.dataForm.updateOpenDate = newval[0];
          this.dataForm.updateEndDate = newval[1];
        }
      } else {
        this.dataForm.updateOpenDate = "";
        this.dataForm.updateEndDate = "";
      }
    },
  },
  filters: {
    delStatus(val) {
      let d = that.payState.filter((item) => item.val == val);
      if (d[0]) {
        return d[0].label;
      } else {
        return "";
      }
    },
  },
  methods: {
    getScenicOptions() {
      this.$http
        .get("scenic/isscenic/selectScenicList", {})
        .then(({ data: res }) => {
          if (res.msg == "success") {
            console.log(res);
            this.scenicOptions = res.data;
          }
        });
    },
    viewHandle(row) {
      if (row.orderCode) {
        this.orderCode = row.orderCode;
      }
      let url = "";
      let type = "";
      if (row.orderType == 1) {
        //景区门票
        url = "/scenic/scenic-order/queryScenicTicketDetails";
        type = "1";
      } else if (row.orderType == 7) {
        url = "/scenic/scenic-order/getSsOrderInfo/";
        type = "2";
      }
      this.url = url;
      this.type = type;

      this.lookDetail(row.id);
    },
  },
};
</script>
